package com.wei.ssm.controller;

import com.github.pagehelper.PageInfo;
import com.wei.ssm.domain.Orders;
import com.wei.ssm.domain.Role;
import com.wei.ssm.service.IOrdersService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;

import java.util.List;

@Controller
@RequestMapping("/orders")
public class OrderController {

    @Autowired
    private IOrdersService iOrdersService;





    @RequestMapping("/findById.do")
    public ModelAndView findById(@RequestParam(name = "id",required = true) int id) throws Exception {
        ModelAndView modelAndView = new ModelAndView();

        System.out.println();
        //查询一个订单回来
        Orders order = iOrdersService.findById(id);
        modelAndView.addObject("orders",order);
        modelAndView.setViewName("orders-show");
        return modelAndView;
    }

    @RequestMapping("/findAll.do")
    public ModelAndView findAll(@RequestParam(name = "page",required = true,defaultValue = "1") Integer page, @RequestParam(name = "size",required = true,defaultValue = "10") Integer pageSize){
        ModelAndView modelAndView = new ModelAndView();

        List<Orders> ordersList = iOrdersService.findAllByPage(page,pageSize);
        PageInfo<Orders> pageInfo = new PageInfo<Orders>(ordersList);
        modelAndView.addObject("pageInfo",pageInfo);
        modelAndView.setViewName("orders-page-list");
        return modelAndView;

    }
}
